#!/bin/bash

# 执行 is_free 字段修复脚本

echo "======================================"
echo "修复 is_free 字段数据"
echo "======================================"
echo ""

# 数据库配置
DB_HOST="localhost"
DB_PORT="3306"
DB_USER="root"
DB_PASS="123"
DB_NAME="ry_vue"

echo "执行修复脚本..."
echo ""

# 执行SQL脚本（使用源文件路径）
mysql -h${DB_HOST} -P${DB_PORT} -u${DB_USER} -p${DB_PASS} ${DB_NAME} < diagnose_and_fix_is_free.sql

if [ $? -eq 0 ]; then
    echo ""
    echo "======================================"
    echo "✅ 修复完成！"
    echo "======================================"
    echo ""
    echo "修复结果："
    echo "- 所有 NULL 值已设置为 '0'（VIP）"
    echo "- 33个基础词典已设置为免费"
    echo ""
    echo "下一步："
    echo "1. 重启后端服务"
    echo "   ./ry.sh restart"
    echo ""
    echo "2. 测试接口（应该只返回免费词典）"
    echo "   curl http://localhost:8080/module/dict/book/user/list?languageCategory=en"
    echo ""
else
    echo ""
    echo "❌ 执行失败"
    echo "请检查数据库连接"
    echo ""
fi

